package cn.com.reflect;
//        获取成员方法
//        Method[] getMethods()
//        Method getMethod(String name, 类<?>... parameterTypes)
//        Method[] getDeclaredMethods()
//        Method getDeclaredMethod(String name, 类<?>... parameterTypes)
//        获取类名
//        getName()

import cn.com.domain.Person;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class ReflectDemo4 {
    public static void main(String[] args) throws Exception {
        //获取Person的Class对象
        Class personClass = Person.class;
        Method eatMethod = personClass.getMethod("eat");
        Person person = new Person();
        eatMethod.invoke(person); //eat

        Method eatMethod2 = personClass.getMethod("eat", String.class);
        //执行方法
        eatMethod2.invoke(person, "饭");

        System.out.println("----------------------");

        //获取所有public修饰的方法
        Method[] methods = personClass.getMethods();
        for (Method method : methods) {
            String name = method.getName();
            System.out.println(name);
            System.out.println(method);
        }

        //获取雷鸣
        String className = personClass.getName();
        System.out.println(className); //domain.Person
    }
}
